package net.apps123.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import net.apps123.soundmeter.R;

import java.util.ArrayList;
import java.util.List;

public class SplAdapter extends BaseAdapter {

    private Context context;
    private List<SplDataBean> datas = new ArrayList<>();

    public SplAdapter(Context context, List<SplDataBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        if (datas != null) {
            return datas.size();
        }
        return 0;
    }

    @Override
    public SplDataBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_spl_layout, parent,false);
            holder = new ViewHolder();
            holder.splView = (SplView) convertView.findViewById(R.id.splView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//        Short[] arr = datas.get(position).toArray(new Short[datas.get(position).size()]);
//        short[] updateData = new short[arr.length];
//        for (int i=0; i<arr.length; i++){
//            updateData[i] = arr[i];
//        }
        holder.splView.updateView( datas.get(position).getData(), datas.get(position).getIpStr() );
        return convertView;
    }

    private class ViewHolder {
        SplView splView;
    }

}
